package com.seven.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author sevenDay
 * @classname SevenThread
 * @description:
 * @Override public  void run() {
 * LOGGER.info("taskId: {}  ,taskName: {} ",taskId,taskName);
 * try {
 * Thread.sleep(10000);
 * } catch (InterruptedException e) {
 * LOGGER.error("taskId: {}  ,taskName: {} 执行异常,异常信息 {}",taskId,taskName,e.getMessage());
 * LOGGER.error("",e);
 * }
 * }
 * @date 2017/11/20
 */
public abstract class SevenThread extends Thread {

    private static final Logger LOGGER = LoggerFactory.getLogger(SevenThread.class);
    private int taskId;
    private String taskName;
    private long startTime;
    private long endTime;

    /**
     * 用于实现线程执行的过程
     *
     * @return
     * @throws Exception
     */
    @Override
    public abstract void run();

    /**
     * 设置线程的任务Id，可以是严格排序的Id
     *
     * @param taskId
     */
    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }
    public int getTaskId() {
        return this.taskId;
    }
    /**
     * 设置线程的任务名称
     *
     * @param taskName
     */
    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }



    public String getTaskName() {
        return this.taskName;
    }



    /**
     * 设置线程开始执行时间，用于统计线程执行效率
     *
     * @param startTime
     */
    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }



    public long getStartTime() {
        return this.startTime;
    }



    /**
     * 设置线程执行结束的时间，便于统计线程的执行效率和任务耗时量
     *
     * @param endTime
     */
    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }



    public long getEndTime() {
        return this.endTime;
    }



    public SevenThread(int taskId, String taskName) {
        this(taskId, taskName, true);
    }

    public SevenThread(int taskId, String taskName, boolean daemon) {
        this.taskId = taskId;
        this.taskName = taskName;
        this.setDaemon(daemon);

    }

    public SevenThread() {
    }
    public long getExecuteTime(){
        return  this.endTime-this.startTime;
    }
}
